<?php

namespace App\Http\Resources\App;

use Illuminate\Http\Resources\Json\JsonResource;

class CourseResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return ['id' => $this->id, 'title' => $this->title, 'description' => $this->description, 'course_type' => $this->course_type, 'course_type_text' => $this->course_type_text, 'content_type' => $this->content_type, 'learn_count' => $this->users[0]->pivot->learn_count ?? 0, 'is_completed' => !empty($this->users[0]->pivot->completed_at), 'pivot' => $this->pivot];
    }
}
